package mydev

import (
	"fmt"
	"time"
)

type TrackTime struct {
	title string
	//开始计时的时间
	TrackStartTime time.Time `json:"track_start_time"`
}

func NewTrackTime(title_ string) *TrackTime {
	return &TrackTime{title: title_}
}

// StartTrack 开始计时
func (s *TrackTime) StartTrack() {
	s.TrackStartTime = time.Now()
}

// EndTrack 结束计时
func (s *TrackTime) EndTrack() time.Duration {
	elapsed := time.Since(s.TrackStartTime)
	fmt.Println(s.title+"执行耗时：:", elapsed)
	return elapsed
}

// ------------------------------全局的计时------------------
var startTime time.Time

func StartTrack() {
	startTime = time.Now()
}
func EndTrack() time.Duration {
	elapsed := time.Since(startTime)
	fmt.Println("执行耗时：:", elapsed)
	return elapsed
}
